<template>
<div class="register">
    <Form ref="formInline" :model="user" :rules="ruleInline"  
    :label-width="80">
        <FormItem prop="username" label="用户名">
            <Input type="text" v-model="user.username" placeholder="Username" >
               
            </Input>
        </FormItem>
        <FormItem prop="password" label="密码">
            <Input type="password" v-model="user.password" placeholder="Password" >
                
            </Input>
        </FormItem>
        <FormItem prop="passwordb" label="确认密码">
            <Input type="password" v-model="user.passwordb" placeholder="Password" >
                
            </Input>
        </FormItem>
        <FormItem prop="email" label="E-mail">
            <Input type="text" v-model="user.email" placeholder="email" >
               
            </Input>
        </FormItem>
        <FormItem >
            <Button type="primary" style="margin-left:100px;"  @click="register">注册</Button>
            <Button type="ghost" @click="login" style="margin-left: 8px">登录</Button>
            
        </FormItem>
    </Form>
</div>
</template>
<script>
export default {
    head(){
        return {
            title:'注册'
        }
    },data(){
        return {
            
            user: {
                username:'',password:''
            },
            ruleInline: {
                username: [
                    { required: true, message: 'Please fill in the user name', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: 'Please fill in the password.', trigger: 'blur' },
                    { type: 'string', min: 4, message: 'The password length cannot be less than 6 bits', trigger: 'blur' }
                ]
            }
        }  
    },
    methods:{
      login(){
          this.$router.push('/login')
      },
      register(){
        axios.post('/login/register',this.user).then(res=>{
                console.log(res);
                if(res.errorCode==0){
                    this.$store.commit('setuser', res.data);
                    var t=this.$route.query.redirect || '/';
                    this.$router.push(t);
                }
        })
      }
  }
}
</script>
